<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{{ site.title }}</title>
    <link rel="stylesheet" href="/stylesheets/style.css">
    {{include 'components/import'}}
    <script src="/javascripts/validator.min.js"></script>
</head>
<body>
    <!-- {{include 'components/site-nav'}} -->
    {{include 'components/header'}}
    <div class="list-tab container-fluid" id="StoreTab">
        <ul class="nav container" role="tablist">
          <li role="presentation" class="active"><a href="#per-base" role="tab" data-toggle="tab" aria-expanded="true">基本信息</a></li>
          <li role="presentation" class=""><a href="#per-pub" role="tab" data-toggle="tab" aria-expanded="false">我的发布</a></li>
          <li role="presentation" class=""><a href="#per-fav" role="tab" data-toggle="tab" aria-expanded="false">我的收藏</a></li>
        </ul>
      </div>
      <div class="container-fluid form-con" id="perCenter">
        <div class="container">
          <div class="tab-content">
            <div role="tabpanel" class="tab-pane active" id="per-base">
              {{ if userinfo }}
              <dl class="dl-horizontal">
                <dt>用户名：</dt>
                <dd>{{userinfo.username}}</dd>
                <dt>用户邮箱：</dt>
                <dd>{{userinfo.email}}</dd>
                <dt>真实姓名：</dt>
                <dd>{{userinfo.name}} {{'female' == userinfo.gender ? '女士' : ('male' == userinfo.gender ? '先生' : '')}}</dd>
                <dt>联系电话：</dt>
                <dd>{{userinfo.phone}}</dd>
                <dt>联系地址：</dt>
                <dd>{{userinfo.address}}</dd>
                <dt>&nbsp;</dt>
                <dd>
                  <a href="javascript:;" class="btn btn-theme" data-toggle="modal" data-target="#password">修改密码</a>
                  <a href="javascript:;" class="btn btn-theme" data-toggle="modal" data-target="#infoEdit">修改信息</a>
                  <a href="javascript:loginOut();" class="btn btn-match">退出登录</a>
                </dd>
              </dl>
              {{ else }}
                请先登录 <a href="/{{ site.subDomain }}/signin">登录</a>
              {{ /if }}
            </div>
            <div role="tabpanel" class="tab-pane" id="per-pub">
              <div class="list-so row">
                <div class="col-xs-6 col-sm-3">
                  <a href="javascript:deleteMany();" class="btn btn-theme"><i class="fa fa-trash-o"></i></a>
                </div>
                <div class="col-xs-6 col-sm-3 text-right">
                  <div class="dropdown">
                    <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
                      转让
                      <span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenu1">
                      <li class="active"><a href="#">转让</a></li>
                      <li><a href="#">出租</a></li>
                      <li><a href="#">出售</a></li>
                      <li role="separator" class="divider"></li>
                      <li><a href="#">求租</a></li>
                      <li><a href="#">求售</a></li>
                    </ul>
                  </div>
                </div>
                <div class="col-xs-12 col-sm-6">
                  <div class="input-group">
                    <span class="input-group-addon" id="sizing-addon2"><i class="fa fa-search"></i></span>
                    <input type="text" class="form-control" id="inputSearch1" placeholder="请输入标题进行搜索...">
                  </div>
                </div>
              </div>
              <div class="table-responsive">
                <table class="table">
                  <thead>
                    <tr>
                      <th><input type="checkbox" class="check-all" value="Attorn"></th>
                      <th>标题</th>
                      <th>面积</th>
                      <th>租金</th>
                      <th>浏览收藏</th>
                      <th>操作</th>
                    </tr>
                  </thead>
                  <tbody>

                    {{ each info_person.pageDatas data}}
                    <tr data-did="{{@ data._id }}">
                      <td><input type="checkbox" value="{{@ data._id }}"></td>
                      <td>
                        <dl class="dl-horizontal">
                          <dt style="height:60px;">
                              {{ if data.images }}
                              <img style="height:auto;" src="{{ data.images[0] | watermark}}">
                              {{ else }}
                              <img style="height:auto;" src="images/1.jpg">
                              {{ /if }}
                          </dt>
                          <dd>
                            <a href="/{{ site.subDomain }}/detail/{{@ data._id }}">{{ data.title }}</a>
                            <p class="ar">
                              {{ if data.infoType == "Attorn" }}
                                  <strong>[转让]</strong>
                                  <span>{{ data.estate.district }} {{ data.estate.shopArea }}</span>
                                  <span> {{ data.estate.type }} </span>
                                  {{ else if data.infoType == "SeekLease" }}
                                  <strong>[求租]</strong>
                                  <span>{{ data.estate.district[0] }} {{ data.estate.shopArea[0] }}</span>
                                  <span> {{ data.estate.type[0] }} </span>

                              {{ /if }}
                            </p>
                            <p><span class="time"><i class="fa fa-clock-o"></i>{{ data.createdAt | dateFormat }}</span><p>
                          </dd>
                        </dl>
                      </td>
                      {{ if data.estate.area.min }}
                          <td class="area"><strong>{{ data.estate.area.min }}~{{ data.estate.area.max }}</strong>m<sup name="">2</sup></td>
                          {{ else }}
                          <td class="area"><strong>{{ data.estate.area }}</strong>m<sup name="">2</sup></td>
                      {{ /if }}

                      {{ if data.estate.transferFee.min }}
                          <td class="price"><strong>{{ data.estate.transferFee.min }}~{{ data.estate.transferFee.max }}</strong><span>元/月</span></td>
                          {{ else }}
                          <td class="price"><strong>{{ data.estate.transferFee * 10000 }}</strong><span>元/月</span></td>
                      {{ /if }}


                      <td class="view"><p><i class="fa fa-heart"></i>

                          {{ if data.watchCount}}
                          {{ data.watchCount }}
                          {{ else }}
                          0
                          {{ /if }}
                      </p><p><i class="fa fa-eye"></i>
                          {{ if data.viewCount}}
                          {{ data.viewCount }}
                          {{ else }}
                          0
                          {{ /if }}
                          </p></td>
                      <td class="do">
                        <a href="/{{ site.subDomain }}/edit/{{@ data._id }}"><i class="fa fa-edit"></i></a>
                        <a data-reid="{{@ data._id }}" class="delete-release" href="javascript:;"><i class="fa fa-trash-o"></i></a>
                      </td>
                    </tr>
                    {{ /each }}

                  </tbody>
                </table>
              </div>
              <nav aria-label="Page navigation">
                <ul class="pagination my-release">

                </ul>
              </nav>
            </div>
            <div role="tabpanel" class="tab-pane" id="per-fav">

              <div class="list-so row">
                <div class="col-xs-6 col-sm-3">
                  <a href="javascript:deleteColletMany();" class="btn btn-theme"><i class="fa fa-trash-o"></i></a>
                </div>
                <div class="col-xs-6 col-sm-3 text-right">

                </div>
                <div class="col-xs-12 col-sm-6">
                  <div class="input-group">
                    <span class="input-group-addon" id="sizing-addon3"><i class="fa fa-search"></i></span>
                    <input type="text" class="form-control" id="inputSearch2" placeholder="请输入标题进行搜索...">
                  </div>
                </div>
              </div>
              <div class="table-responsive">
                <table class="table">
                  <thead>
                    <tr>
                      <th><input type="checkbox" class="check-all" value="collect"></th>
                      <th>标题</th>
                      <th>面积</th>
                      <th>租金</th>
                      <th>操作</th>
                    </tr>
                  </thead>
                  <tbody>
                      {{ if info_collect }}
                      {{ each info_collect data }}
                    <tr>
                      <td><input type="checkbox" value="{{@ data._id }}"></td>
                      <td>
                        <dl class="dl-horizontal">
                            <dt>
                                {{ if data.images && data.images.length > 0}}
                                <img style="height:auto;" src="{{ data.images[0] | watermark}}">
                                {{ /if }}
                            </dt>

                          <dd>
                            <a href="/{{ site.subDomain}}/detail/{{@ data._id}}"> {{ data.title }}</a>
                            <p class="ar">
                                {{ if data.infoType == 'Attorn'}}
                                  <strong>[转让]</strong>
                                  <span>{{ data.estate.district }} {{ data.estate.shopArea }}</span>
                                  <span>{{ data.estate.type }}</span>
                                  {{ else }}
                                  <strong>[求租]</strong>
                                  <span>{{ data.estate.district[0] }} {{ data.estate.shopArea[0] }}</span>
                                  <span>{{ data.estate.type[0] }}</span>
                                {{ /if }}

                            </p>
                            <p>
                                {{ if data.isPreference == true }}
                                <span class="att ok">
                                    <i class="fa fa-check"></i>腾铺认证信息
                                </span><p>
                                    {{ else }}
                                    <span class="att">网友个人信息</span>
                                {{ /if }}
                          </dd>
                        </dl>
                      </td>
                      {{ if data.infoType == 'Attorn'}}
                      <td class="area"><strong>{{ data.estate.area }}</strong>m<sup name="">2</sup></td>
                      <td class="price"><strong>{{ data.estate.rental }}</strong><span>元/月</span></td>
                        {{ else }}
                        <td class="area"><strong>{{ data.estate.area.min }}-{{ data.estate.area.max }}</strong>m<sup name="">2</sup></td>
                        <td class="price"><strong>{{ data.estate.rental.min }}-{{ data.estate.rental.max }}</strong><span>元/月</span></td>
                      {{ /if }}

                      <td class="do">
                        <a href="javascript:;" data-uname="{{ data.contact.name }}" data-phone="{{ data.contact.phone }}" data-gender="{{data.contact.gender }}" class="contact" data-toggle="popover"><i class="fa fa-phone"></i></a>
                        <a class="deleteCollec" data-pid="{{@ data._id }}" href="javascript:;"><i class="fa fa-trash-o"></i></a>
                      </td>
                    </tr>
                    {{ /each }}
                    {{ /if }}

                  </tbody>
                </table>
              </div>

            </div>

          </div>
        </div>
      </div>


      {{include 'components/footer'}}

      <!-- password -->
      <div class="modal fade" id="password" tabindex="-1" role="dialog" aria-labelledby="passwordLabel">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <form id="repasswordForm">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">修改密码</h4>
              </div>
              <div class="modal-body">
                <div class="form-horizontal">
                  <div class="form-group">
                    <label for="inputPasswordOrigin" class="col-sm-3 control-label">原密码：</label>
                    <div class="col-sm-6">
                      <input type="password" class="form-control" id="inputPasswordOrigin" name="originpwd" placeholder="原密码" required>
                    </div>
                  </div>
                  <div class="form-group">
                    <label for="inputPasswordNew" class="col-sm-3 control-label">新密码：</label>
                    <div class="col-sm-6">
                      <input type="password" class="form-control" id="inputPasswordNew" name="newpwd" placeholder="新密码" required>
                    </div>
                  </div>
                  <div class="form-group">
                    <label for="inputPasswordRepeat" class="col-sm-3 control-label">确认密码：</label>
                    <div class="col-sm-6">
                      <input type="password" class="form-control" id="inputPasswordRepeat" name="confirmpwd" placeholder="确认密码" required>
                    </div>
                  </div>
                </div>
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-theme" id="repasswordFormSubmit">确认修改</button>
              </div>
            </form>
          </div>
        </div>
      </div>



      <!-- infoEdit -->
      <div class="modal fade" id="infoEdit" tabindex="-1" role="dialog" aria-labelledby="infoEditLabel">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <form id="modifyInfoForm">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">修改个人信息</h4>
              </div>
              <div class="modal-body">
                <div class="form-horizontal">
                  <div class="form-group">
                    <label for="inputReUserame" class="col-sm-3 control-label">用户名：</label>
                    <div class="col-sm-6">
                      <input type="text" class="form-control" id="inputReUserame" name="newusername" placeholder="用户名" disabled="disabled">
                    </div>
                  </div>

                  <div class="form-group">
                    <label for="inputReEmail" class="col-sm-3 control-label">用户邮箱：</label>
                    <div class="col-sm-6">
                      <input type="email" class="form-control" id="inputReEmail" name="email" placeholder="用户邮箱" data-error="请输入正确的邮箱地址">
                    </div>
                  </div>
                  <div class="form-group">
                    <label for="inputReName" class="col-sm-3 control-label">真实姓名：</label>
                    <div class="col-sm-6">
                      <input type="text" class="form-control" id="inputReName" name="name" placeholder="真实姓名">
                    </div>
                  </div>
                  <div class="form-group">
                    <label for="gender" class="col-sm-3 control-label">性别：</label>
                    <div class="col-sm-6">
                      <label class="checkbox-inline">
                        <input type="radio" id="male" name="gender" value="male"> 先生
                      </label>
                      <label class="checkbox-inline">
                        <input type="radio" id="female" name="gender" value="female"> 女士
                      </label>
                    </div>
                  </div>
                  <div class="form-group">
                    <label for="inputReAddress" class="col-sm-3 control-label">联系地址：</label>
                    <div class="col-sm-6">
                      <input type="text" class="form-control" name="address" id="inputReAddress" placeholder="联系地址">
                    </div>
                  </div>
                  <div class="form-group">
                    <label for="inputRePhone" class="col-sm-3 control-label">联系电话：</label>
                    <div class="col-sm-6">
                      <input type="tel" pattern="^[0-9-]{8,13}$" class="form-control" id="inputRePhone" name="phone" placeholder="联系电话" data-error="请输入正确的电话号码">
                    </div>
                  </div>
                </div>
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="submit" class="btn btn-theme" id="modifyInfoFormSubmit">确认修改</button>
              </div>
            </form>
          </div>
        </div>
      </div>

    <script type="text/javascript">
    function createHtml(){
        console.log(this);
        var self = $(this);
        var uname = self.data('uname');
        // var gender = self.data('gender') == 'meal'?'先生':'女士';
        var phone = self.data('phone');
        var html = "<p>"+uname+"</p><div>"+phone+"</div>";
        return html;
    }
    function dateFormat(UTCDateString) {
        if (!UTCDateString) {
            return '-';
        }

        function formatFunc(str) { //格式化显示
            return str > 9 ? str : '0' + str
        }
        var date2 = new Date(UTCDateString); //这步是关键
        var year = date2.getFullYear();
        var mon = formatFunc(date2.getMonth() + 1);
        var day = formatFunc(date2.getDate());
        var hour = date2.getHours();
        // var noon = hour >= 12 ? 'PM' : 'AM';
        // hour = hour>=12?hour-12:hour;
        hour = formatFunc(hour);
        var min = formatFunc(date2.getMinutes());
        var sec = formatFunc(date2.getSeconds());
        var dateStr = year + '-' + mon + '-' + day + ' ' + ' ' + hour + ':' + min + ':' + sec;
        return dateStr;
    };
      $(document).ready(function(){
        // TODO 定制弹出内容
        $('#per-fav .contact').popover(
          {
            trigger:'click', //触发方式
            placement: 'bottom',
            //title:"联系方式：",//设置 弹出框 的标题
            html: true, // 为true的话，data-content里就能放html代码了
            content: createHtml,//这里可以直接写字符串，也可以 是一个函数，该函数返回一个字符串；
          }
        );
        console.log('{{ info_person }}');
        console.log('userName: ', userName);
        // 没有用户登陆跳到登陆页
        if (!userName) {
          // return;
          location.href = '/signin';
        }

        else {
          // 用户信息填充
          $('#inputReUserame').val(userName);
          $('#inputReEmail').val(loginUser['email']);
          $('#inputReName').val(loginUser['name']);

          if ('male' == loginUser['gender']) {
            $('#male').attr('checked', true);
          }
          else if ('female' == loginUser['gender']) {
            $('#female').attr('checked', true);
          }
          $('#inputReAddress').val(loginUser['address']);
          $('#inputRePhone').val(loginUser['phone']);
        }

        var submiting = false;
        $('#repasswordFormSubmit').click(function () {
          if (submiting) {
            return;
          }

          submiting = true;

          // $('#repasswordForm').submit();

          var formdata = $('#repasswordForm').serializeArray()
          var postdata = {}
          for(var i = 0; i < formdata.length; i++) {
              postdata[formdata[i].name] = formdata[i].value
          }

          if (!postdata.originpwd || !postdata.newpwd || !postdata.confirmpwd) {
            bootbox.alert('请填写密码');
            return;
          }

          if (postdata.newpwd != postdata.confirmpwd) {
            bootbox.alert('2次新密码不一致');
            return;
          }

          postdata.username = userName;
        //   var info_person = '{{ info_person }}';
        //   console.log(info_person);
          $.ajax({
              type: "PUT",
              url: "{{site_addr}}/changepwd",
              data: postdata,
              success: function (data, textStatus) {
                  if (data.ok) {
                    $('#password').modal('hide');
                    bootbox.alert('密码修改成功');

                    $('#repasswordForm').find('input').val('');
                  }
                  else {
                    bootbox.alert(data.msg);
                  }
              },
              complete: function (XMLHttpRequest, textStatus) {
                  submiting = false;
              }
          });
          return false;
        });


        $('#modifyInfoForm').validator().on('submit', function (e) {
          if (e.isDefaultPrevented()) {
            return false;
          }
          if (submiting) {
            return;
          }

          submiting = true;
          var formdata = $('#modifyInfoForm').serializeArray();
          var postdata = {}
          for(var i = 0; i < formdata.length; i++) {
              postdata[formdata[i].name] = formdata[i].value
          }

          $.ajax({
              type: "PUT",
              url: "{{site_addr}}/user/" + userName,
              data: postdata,
              success: function (data, textStatus) {
                  if (data.ok) {
                    $('#modifyInfoForm').modal('hide');
                    bootbox.alert('个人信息修改成功');

                    // $('#modifyInfoForm').find('input').val('');
                    location.reload();
                  }
                  else {
                    bootbox.alert(data.msg);
                  }
              },
              complete: function (XMLHttpRequest, textStatus) {
                  submiting = false;
              }
          });
          return false;
        });
      });


      var pageIndex = '{{@ info_person.pageInfo.pageIndex}}';
      var totalPage = '{{@ info_person.pageInfo.totalPage}}';
      var myReleasePage = $('.my-release');
      function pageMain(total,index){
          var html = '<li class="disabled"><a href="#" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>';
          for (var i = 0; i < total; i++) {
              if ( i+1 == index ) {
                  html += '<li class="active"><a data-page = "'+(i+1)+'" href="javascript:;">'+(i+1)+'<span class="sr-only">(current)</span></a></li>';
              } else {
                  html += '<li><a data-page = "'+(i+1)+'" href="javascript:;">'+(i+1)+'</a></li>';
              }
          }
          html += '<li><a href="#" aria-label="Next"><span aria-hidden="true">&raquo;</span></a></li>';
          myReleasePage.html('');
          myReleasePage.append(html);
      }
      pageMain(totalPage,pageIndex);
      function pageNew(){
          var self = this;
          var page = $(self).data('page');
          var data = $('#inputSearch1').val();
          if (data) {
              console.log(data.split(' '))
              var q = data.split(' ');
              setquery(q,page)
          } else {
              setquery('',page)
          }

      }
      myReleasePage.on('click','a',pageNew)
      function deleteRelease(){
          console.log(this)
              var parent = $(this).parents('tr');
              var pid = $(this).data('reid');
              $.ajax({
                  type: "delete",
                  contentType: "application/json",
                  url: SITE_ADDR + "/info/"+pid,
                  success: function (data, textStatus) {
                      if (data.ok) {
                          parent.remove();
                      }
                      else {
                      }
                  },
                  complete: function (XMLHttpRequest, textStatus) {
                      submiting = false;
                  }
              });
      }
      function deleteMany(){
          var checkboxbtn = $('input[type=checkbox]:checked');
          var parents = $('input[type=checkbox]:checked').parents('tr');
          console.log(parents);
          var ids = [];
          for (var i = 0; i < checkboxbtn.length; i++) {
              ids[i] = checkboxbtn[i].value;
          }
          console.log(ids);
          if ( ids.length > 0 ) {
              $.ajax({
                  type: "delete",
                  contentType: "application/json",
                  url: SITE_ADDR + "/infos/"+ids,
                  success: function (data, textStatus) {
                      if (data.ok) {
                        for (var i = 0; i < parents.length; i++) {
                            $(parents[i]).remove();
                        }
                      }
                      else {
                      }
                  },
                  complete: function (XMLHttpRequest, textStatus) {
                      submiting = false;
                  }
              });
          }
      }
      function deleteColletMany(){
          var userid = loginUser._id;
          var checkboxbtn = $('tbody input[type=checkbox]:checked');
          var parents = $('tbody input[type=checkbox]:checked').parents('tr');
          console.log(parents);
          var pid = [];
          for (var i = 0; i < checkboxbtn.length; i++) {
              pid[i] = checkboxbtn[i].value;
          }
          $.ajax({
              type: "delete",
              contentType: "application/json",
              url: SITE_ADDR + "/user/"+userid+"/"+pid+"/delcollect",
              success: function (data, textStatus) {
                  if (data.ok) {
                      for (var i = 0; i < parents.length; i++) {
                          $(parents[i]).remove();
                      }
                  }
                  else {
                  }
              },
              complete: function (XMLHttpRequest, textStatus) {
                  submiting = false;
              }
          });
      }
      function deleteCollet(){
          var parent = $(this).parents('tr');
          var pid = $(this).data('pid');
          var userid = loginUser._id;


          $.ajax({
              type: "delete",
              contentType: "application/json",
              url: SITE_ADDR + "/user/"+userid+"/"+pid+"/delcollect",
              success: function (data, textStatus) {
                  if (data.ok) {
                      parent.remove();
                  }
                  else {
                  }
              },
              complete: function (XMLHttpRequest, textStatus) {
                  submiting = false;
              }
          });
      }
      function setquery(keyword,page,ids,target) {
          var q = {
              query: {
                  user: userName,
              },
              sort: {
                  createdAt: -1
              },
              page: {
                  index: page?page:1,
                  size: 10
              }
          };
          if (keyword) {
              q.query.title = keyword;
              q.query.content = keyword;
          }
          if (ids) {
              q.query.ids = ids;
              delete q.query.user;
          }
          console.log(q)
          $.ajax({
              type: "get",
              contentType: "application/json",
              url: SITE_ADDR + "/infos/"+JSON.stringify(q)+"/search",
              success: function (data, textStatus) {
                  console.log(data)
                  mosaicPerPub(data,target)
                  pageMain(data.pageInfo.totalPage,data.pageInfo.pageIndex);
              },
              complete: function (XMLHttpRequest, textStatus) {
                  submiting = false;
              }
          });
      }
      function mosaicPerPub(data,target) {
          var pageDatas = data.pageDatas;
          if (pageDatas.length > 0) {
              if (target == 'collect') {
                  $('#per-fav tbody').html('');
              } else {
                  $('#per-pub tbody').html('');
              }
              for (var i = 0; i < pageDatas.length; i++) {
                  var html = '<tr data-did="'+pageDatas[i]._id+'">'
                      html += '<td><input type="checkbox" value="'+pageDatas[i]._id+'"></td>'
                      html += '<td>'
                      html += '<dl class="dl-horizontal">'
                      html +=  '<dt>'
                      html += '<img src="'+pageDatas[i].images[0]+'">'
                      html += '</dt>'
                      html += '<dd>'
                      html += '<a href="/'+CITY+'/detail/'+pageDatas[i]._id+'">'+pageDatas[i].title+'</a>'
                      html += '<p class="ar">'
                                if (pageDatas[i].infoType == 'Attorn') {
                                    html += '<strong>[转让]</strong>'
                                    html += '<span> '+pageDatas[i].estate.district+' '+ pageDatas[i].estate.shopArea+'</span>'
                                    html += '<span>'+pageDatas[i].estate.type+'</span>'
                                } else {
                                    html += '<strong>[求租]</strong>'
                                    html += '<span> '+pageDatas[i].estate.district[0]+' '+ pageDatas[i].estate.shopArea[0]+'</span>'
                                    html += '<span>'+pageDatas[i].estate.type[0]+'</span>'
                                }
                       html += '</p>'
                       html += '<p><span class="time"><i class="fa fa-clock-o"></i>'+dateFormat(pageDatas[i].createdAt)+'</span><p>'
                       html += '</dd>'
                       html += '</dl>'
                       html += '</td>'
                    if (pageDatas[i].estate.area.min) {
                        html += '<td class="area"><strong>'+pageDatas[i].estate.area.min +'~'+pageDatas[i].estate.area.max+'</strong>m<sup name="">2</sup></td>'
                    } else {
                        html += '<td class="area"><strong>'+pageDatas[i].estate.area+'</strong>m<sup name="">2</sup></td>'
                    }
                    if (pageDatas[i].estate.transferFee.min) {
                        html += '<td class="price"><strong>'+pageDatas[i].estate.transferFee.min+'~'+ pageDatas[i].estate.transferFee.max+'</strong><span>元/月</span></td>'
                    } else {
                        html += '<td class="price"><strong>'+pageDatas[i].estate.transferFee+'</strong><span>万元/月</span></td>'
                    }
                    if (target != 'collect') {
                        html += '<td class="view">'
                        if (pageDatas[i].watchCount) {
                            html += '<p><i class="fa fa-heart"></i>'
                                +pageDatas[i].watchCount+
                            '</p>'
                        } else {
                            html += '<p><i class="fa fa-heart"></i>0</p>'
                        }
                        if (pageDatas[i].viewCount) {
                            html += '<p><i class="fa fa-eye"></i>'+pageDatas[i].viewCount+'</p>'
                        } else {
                            html += '<p><i class="fa fa-eye"></i>0</p>'
                        }

                        html += '</td>'
                    }

                    html += '<td class="do">'
                    html += '<a href="/'+CITY+'/edit/'+pageDatas[i]._id+'"><i class="fa fa-edit"></i></a>'
                    html += '<a data-reid="'+pageDatas[i]._id+'" class="delete-release" href="javascript:;"><i class="fa fa-trash-o"></i></a>'
                    html += '</td>'
                    html += '</tr>';
                    console.log(html)
                    if (target == 'collect') {
                        $(html).appendTo('#per-fav tbody');
                    } else {
                        $(html).appendTo('#per-pub tbody');
                    }

              }
          } else {
              $('#per-pub tbody').html('');
          }
      }
      $('#sizing-addon3').on('click',function(){
          var data = $('#inputSearch2').val();
          if (data) {
              console.log(data.split(' '))
              var q = data.split(' ');
              var ids = loginUser.pub
              setquery(q,'',ids,'collect')
          }

        //   location.href = '/'+CITY+'/search?query='+q;
      })
      $('#sizing-addon2').on('click',function(){
          var data = $('#inputSearch1').val();
          if (data) {
              console.log(data.split(' '))
              var q = data.split(' ');
              setquery(q)
          }
      })



      $('#per-pub').on('click','.check-all',function(){
          if (this.checked) {
              $('#per-pub tbody input[type=checkbox]').prop('checked',true);
          } else {
              $('#per-pub tbody input[type=checkbox]').prop('checked',false);
          }

      })
      $('#per-fav').on('click','.check-all',function(){
          if (this.checked) {
              $('#per-fav tbody input[type=checkbox]').prop('checked',true);
          } else {
              $('#per-fav tbody input[type=checkbox]').prop('checked',false);
          }

      })
      $('.delete-release').on('click',deleteRelease)
      $('.deleteCollec').on('click',deleteCollet)
    </script>

</body>
</html>
